package com.zhouxiaoge.reactive;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Flow;
import java.util.concurrent.SubmissionPublisher;

public class SubmissionPublisherExample {
    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(1);
        SubmissionPublisher<String> sb = new SubmissionPublisher<>(executor, Flow.defaultBufferSize());
        try (sb) {
            sb.subscribe(new MySubscriber());   //建立订阅关系，可以有多个订阅者
            sb.submit("数据 1");  //发送消息1
            sb.submit("数据 2"); //发送消息2
            sb.submit("数据 3"); //发送消息3
        }
        executor.shutdown();
    }
}
